// Fill out your copyright notice in the Description page of Project Settings.


#include "AI/Service/TUChangeWeaponService.h"
#include "Component/TUWeaponComponent.h"
#include "AIController.h"
#include "TUUtils.h"

UTUChangeWeaponService::UTUChangeWeaponService()
{
    NodeName = "Change Weapon";
}

void UTUChangeWeaponService::TickNode(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory, float DeltaSeconds)
{
    if (const auto Controller = OwnerComp.GetAIOwner())
    {
        const auto WeaponComponent = TUUtils::GetTUPlayerComponent<UTUWeaponComponent>(Controller->GetPawn());
        if (WeaponComponent && Probability > 0 && FMath::FRand() <= Probability)
        {
            WeaponComponent->NextWeapon();
        }
    }

    Super::TickNode(OwnerComp, NodeMemory, DeltaSeconds);
}
